///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#ifndef __OBJ_OBJECT_LOADER_H__
#define __OBJ_OBJECT_LOADER_H__

//-----------------------------------------------------------------------------

#include <Config.h>
#include <Scene/IObjectLoader.h>
#include <AbstractManager.h>
#include <File/File.h>
#include <Scene/Object.h>
#include <Math/Vec2f.h>
#include <string>
#include <map>

//-----------------------------------------------------------------------------

struct OBJFacePoint
{
	u32		v, t, n;
};

struct OBJFace
{
	std::vector<OBJFacePoint> points;
};

//-----------------------------------------------------------------------------

class OBJObjectLoader
	:	IObjectLoader
	,	public AbstractManager<OBJObjectLoader>
{
	friend class Object;
public:
											OBJObjectLoader();
	virtual									~OBJObjectLoader();

	virtual	bool							CanLoad(File* file);
	virtual bool							Load(File* file);
	virtual	Object*							LoadObject(File* file);

private:
	bool									readData( File* objectFile );
	bool									processData( File* objectFile );

	Vec3f				processVertex ( std::string& s );
	Vec3f				processNorm ( std::string& s );
	Vec2f				processTex ( std::string& s );
	OBJFace				processFace ( std::string& s );
	OBJFacePoint		processFacePoint ( std::string& str );

	std::map<u32,Vec3f>		vertices;
	std::map<u32,Vec3f>		normals;
	std::map<u32,Vec2f>		texcoord;
	std::map<u32,OBJFace>	faces;
	u32					face_count;
	u32					norm_count;
	u32					tex_count;
	u32					vex_count;
};

#endif // __OBJ_OBJECT_LOADER_H__
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
